package com.annotation.configure;

import com.annotation.bean.Color;
import com.annotation.bean.ConstructorApplicationContext;
import com.annotation.bean.Person;
import com.annotation.bean.TestApplicationContextAware;
import com.annotation.condition.CustomerImportBeanDefinitionRegistrar;
import com.annotation.condition.MyImportSelector;
import com.annotation.filter.CustomerTypeFilter;
import com.annotation.repository.TestResitory;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;


/**
 * @ComponentScan value: 指定要扫描的配置类
 * excludeFilters=Filter[]  : 指定扫描的时候按照什么规律排除哪些组件
 * includeFilters=Filter[] : 指定扫描的时候只需要包含哪些组件
 * FilterType=FilterType.ANNOTATION  代表只扫描标注了哪些注解的组件
 * FilterType=FilterType.ASSIGNABLE_TYPE   只包含指定的类型,既包含子类也包含实现类
 * FilterType=FilterType.Customer   自定义匹配器，要实现TypeFilter接口，功能：match()方法 在包扫描下的所有类并且满足自定义功能返回true的类全部注入。
 */
@Configuration
@ComponentScans(
        value = {
                @ComponentScan(value = "com.annotation",
                        includeFilters = {
                                @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class, Service.class}),
                                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {TestResitory.class, TestApplicationContextAware.class}),
                                @ComponentScan.Filter(type = FilterType.CUSTOM, classes = CustomerTypeFilter.class)
                        }, excludeFilters = {
                        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {Person.class})
                }, useDefaultFilters = false)
        }
)
@ComponentScan("com.annotation")
@Import({Color.class, MyImportSelector.class, CustomerImportBeanDefinitionRegistrar.class, ConstructorApplicationContext.class})
public class TestConfig {

    @Bean
    public Person getPerson() {
        Person person = new Person();
        person.setAge(11);
        person.setName("yht");
        return person;
    }


}
